package com.rc.saas.tenant.service.hlht;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.rc.saas.tenant.base.BaseSearch;
import com.rc.saas.tenant.mapper.hlht.HlhtTenantSettingMapper;
import com.rc.saas.tenant.model.hlht.HlhtTenantSetting;
import com.rc.saas.tenant.model.hlht.HlhtTenantSettingExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class HlhtTenantSettingServiceImpl implements HlhtTenantSettingService {

    @Autowired
    private HlhtTenantSettingMapper hlhtTenantSettingMapper;

    @Override
    public PageInfo<HlhtTenantSetting> listPageHlhtTenantSetting(BaseSearch baseSearch) {
        PageHelper.startPage(baseSearch.getOffset(), baseSearch.getLimit());
        HlhtTenantSettingExample example = new HlhtTenantSettingExample();
        List<HlhtTenantSetting> HlhtTenantSettingList = hlhtTenantSettingMapper.selectByExample(example);
        return new PageInfo<HlhtTenantSetting>(HlhtTenantSettingList);
    }

    @Override
    public HlhtTenantSettingMapper getMapper() {
        return hlhtTenantSettingMapper;
    }

    @Override
    public HlhtTenantSetting selectByTenantCodeAndHlhtTenantCodeAndHlhtOperatorId(String tenantCode,String hlhtTenantCode,String hlhtOperatorId) {
        HlhtTenantSettingExample hlhtTenantSettingExample = new HlhtTenantSettingExample();
        hlhtTenantSettingExample.createCriteria().andTenantCodeEqualTo(tenantCode)
                .andHlhtTenantCodeEqualTo(hlhtTenantCode).andHlhtOperatorIdEqualTo(hlhtOperatorId);
        List<HlhtTenantSetting> hlhtTenantSettingList = hlhtTenantSettingMapper.selectByExample(hlhtTenantSettingExample);
        if (hlhtTenantSettingList.size() > 0) {
            return hlhtTenantSettingList.get(0);
        } else {
            return null;
        }
    }
}
